<?php
/**
 * An order object (Datamapper)
 *
 * @author Ishtiaque Shahrier <md.ishtiaque@newgenbd.net>
 * @package order
 * @subpackage models
 */
class discount_info_m_order extends a_base_model_datamapper {

    public function __construct($id=null) {
        $this->table = 'order_discounts';
        $this->has_many = array(
        );
        $this->has_one = array(
        );

        parent::__construct($id);
    }

    public function calculate_discount($order_total){
        $amount = $this->amount;
        $type   = $this->type ;
        if($type=="$"){
            return round($amount,2);
        }elseif($type=="%"){
            return round(($amount*$order_total)/100,2);
        }else{
            logger::i()->warning("Invalid amount type for discount calculation. Discount ID [".$this->id."]","discount");
            return 0.00;
        }
    }
}
?>